<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>天下信用-首页</title>
<%
	String contextPath = request.getContextPath();
%>
</head>
<body>
	主程序
	<a href="javascript:void(0)" onclick="longPulling();" ><img id="qrcode" src="" uuid=""></img></a>
</body>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script>

	 
	//得到二维码
	function get_qrcode(){
		$.ajax({
			url:'<%= contextPath%>/qrLogin',
			type:'POST',
			success:function(data){
				var imgSrc="data:image/png;base64,"+data.base64;
				var uuid = data.uuid;
				$("#qrcode").attr("src",imgSrc);
				$("#qrcode").attr("uuid",uuid);
				//jquery的轮询函数
				//self.setInterval(function(){
					// roll_poling(uuid);
				//},2000);
				//开启连接
				var evtSource = new EventSource("<%= contextPath%>/waitQrLogin/"+uuid);
				evtSource.addEventListener("ready", function (event,data) {
					//close后就不自动重连了，否则就算服务器端对应的方法走完了，还会重新建立连接额
					evtSource.close();
					window.location.href = "http://www.baidu.com";
			    }, false );
			}
		});
	}
	<%--
	//轮询操作
	function roll_poling(uuid){
		$.ajax({
			url:'<%= contextPath%>/member/doQrLogin/'+uuid,
			type:'POST',
			dataType:'JSON',
			success:function(data){
				if( data == "success" ){
					alert("login success");
					window.location.href="http://www.yuorfei.com";
				}	
			}
		});
	} --%>
	window.onload=get_qrcode();
</script>

</html>